﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LcAudit.Common.Data.SqlServer;
using System.Data;
using System.Data.SqlClient;

namespace LcAudit.BPM.Core.Dal
{
    public class materialprice
    {

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string sql,string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(sql);
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return SQLHelper.Query(strSql.ToString());
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(LcAudit.BPM.Core.Model.materialpriceinfo model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into materialpriceinfo(");
            strSql.Append("mpname,mpxh,mpadd,mpnum,mpunit,mprice,bid,bagid)");
            strSql.Append(" values (");
            strSql.Append("@mpname,@mpxh,@mpadd,@mpnum,@mpunit,@mprice,@bid,@bagid)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters = {
					new SqlParameter("@mpname", SqlDbType.NVarChar,100),
					new SqlParameter("@mpxh", SqlDbType.NVarChar,500),
					new SqlParameter("@mpadd", SqlDbType.NVarChar,50),
					new SqlParameter("@mpnum", SqlDbType.Decimal,9),
					new SqlParameter("@mpunit", SqlDbType.NVarChar,10),
					new SqlParameter("@mprice", SqlDbType.Decimal,9),
					new SqlParameter("@bid", SqlDbType.Int,4),
					new SqlParameter("@bagid", SqlDbType.Int,4)};
            parameters[0].Value = model.mpname;
            parameters[1].Value = model.mpxh;
            parameters[2].Value = model.mpadd;
            parameters[3].Value = model.mpnum;
            parameters[4].Value = model.mpunit;
            parameters[5].Value = model.mprice;
            parameters[6].Value = model.bid;
            parameters[7].Value = model.bagid;

            object obj = SQLHelper.GetSingle(strSql.ToString(), parameters);
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }

    }
}
